package com.ruoyi.web.controller.portal;

import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.system.service.ISolrService;
import com.ruoyi.system.service.ISysArticleService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.Map;

/**
 * @PackageName com.ruoyi.web.controller.portal
 * @ClassName ArticlePortalController
 * @Auther jgg
 * @Date 2022-7-25 16:28
 */
@RestController
@RequestMapping("/portal/article")
public class ArticlePortalController extends BaseController {
    @Autowired
    private ISysArticleService articleService;

    @Autowired
    private ISolrService solrService;

    /**
     * 获取置顶文章
     * @return
     */
    @GetMapping("/top")
    public AjaxResult getTopArticle(){
        return articleService.getTopArticle();
    }

    /**
     * 获取发布文章
     * @param pageNo
     * @param pageSize
     * @return
     */
    @GetMapping("/publish")
    public AjaxResult getPublishArticle(Integer pageNo,Integer pageSize,String categoryId,String label){
        return articleService.getPublishArticle(pageNo,pageSize,categoryId,label);
    }

    /**
     * 根据id获取文章
     * @param articleId
     * @return
     */
    @GetMapping("/detail/{articleId}")
    public AjaxResult getArticleDetail(@PathVariable Integer articleId){
        return articleService.getArticleDetailById(articleId);
    }

    /**
     * 搜索文章
     * @param params
     * @return
     */
    @GetMapping("/search")
    public AjaxResult searchArticle(@RequestParam(value = "pageNo", defaultValue = "1") Integer pageNo,
                                    @RequestParam(value = "pageSize", defaultValue = "10") Integer pageSize,
                                    @RequestBody Map<String,Object> params){
        return solrService.searchArticle(pageNo,pageSize,params);
    }
}
